import jsonp from 'common/js/jsonp'
import {commonParams, options} from './config'

export function getSingerList () {
  const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'

  const data = Object.assign({}, commonParams, {
    channel: 'singer',
    page: 'list',
    key: 'all_all_all',
    pagesize: 100,
    pagenum: 1,
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq'
  })

  return jsonp(url, data, options)
}
// 通过不同的歌手id 获取他的数据
export function getSingerDetail (singerId) {
  const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'

  const data = Object.assign({}, commonParams, {
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq',
    order: 'listen',
    begin: 0,
    num: 100,
    songStatus: 1,
    singermid: singerId
  })

  return jsonp(url, data, options)
}
// 获取播放key
export function getVkey (songmid) {
  const url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg'
  const a = 'MusicJsonCallback' + (Math.random() + '').replace('0.', '')

  const data = Object.assign({}, {
    g_tk: 5381,
    inCharset: 'utf-8',
    outCharset: 'utf-8',
    notice: 0,
    format: 'json',
    uin: 0,
    platform: 'yqq',
    needNewCode: 1,
    loginUin: 0,
    hostUin: 0,
    guid: '504753841',
    cid: '205361747',
    filename: 'C100' + songmid + '.m4a',
    songmid: songmid,
    callback: a
  })
  const option = {
    param: 'jsonpCallback',
    name: a
  }
  return jsonp(url, data, option)
}
